package com.ozo.easy.common.exception;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 自定义错误界面返回
 */
@Controller
public class CustomErrorController implements ErrorController {

    @RequestMapping("/error")
    public String handleError(HttpServletRequest request) {
        Integer status = (Integer) request.getAttribute("javax.servlet.error.status_code");
        if (status != null) {
            if (status == 403) {
                return "error/403";
            } else if (status == 404) {
                return "error/404";
            } else if (status == 500) {
                return "error/500";
            }
        }
        return "error";
    }

}